<%--
  $Id: pagination.tag 7 2013-03-04 05:52:15Z gabakyan@gmail.com $
  $Author: gabakyan@gmail.com $
  $Revision: 7 $
  $Date: 2013-03-04 05:52:15 +0000 (Mon, 04 Mar 2013) $

  Copyright (c) 2013 Supply Chain Intelligence (SCI), Inc.
  http://www.scintelligence.com/, Email: info@scintelligence.com
  All rights reserved.

  This file is part of Logistics Map.

  Logistics Map is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, version 3 of the License.

  Logistics Map is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with Logistics Map.  If not, see <http://www.gnu.org/licenses/>.
--%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<%@ attribute name="page" required="true" description="the page number"%>
<%@ attribute name="pageSize" required="true" description="the page size"%>
<%@ attribute name="totalPages" required="true" description="the total pages amount"%>
<%@ attribute name="total" required="true" description="the total amount"%>
<%@ attribute name="baseUrl" required="true" description="the base url"%>

<c:choose>
    <c:when test="${page - 5 > 1}">
        <c:set var="beginPage" value="${page - 5}"/>
    </c:when>
    <c:otherwise>
        <c:set var="beginPage" value="1"/>
    </c:otherwise>
</c:choose>

<c:choose>
    <c:when test="${beginPage + 10 < totalPages}">
        <c:set var="endPage" value="${beginPage + 10}"/>
    </c:when>
    <c:otherwise>
        <c:set var="endPage" value="${totalPages}"/>
    </c:otherwise>
</c:choose>

<c:url var="firstUrl" value="${baseUrl}">
    <c:param name="page" value="1"/>
</c:url>
<c:url var="lastUrl" value="${baseUrl}">
    <c:param name="page" value="${totalPages}"/>
</c:url>
<c:url var="prevUrl" value="${baseUrl}">
    <c:param name="page" value="${page - 1}"/>
</c:url>
<c:url var="nextUrl" value="${baseUrl}">
    <c:param name="page" value="${page + 1}"/>
</c:url>

<%--<div class="pagination pagination-centered">--%>
    <%--<ul>--%>
        <%--<li class="disabled"><a href="#">&laquo;</a></li>--%>
        <%--<li class="active"><a href="#">1</a></li>--%>
        <%--<li><a href="#">2</a></li>--%>
        <%--<li><a href="#">3</a></li>--%>
        <%--<li><a href="#">4</a></li>--%>
        <%--<li><a href="#">5</a></li>--%>
        <%--<li><a href="#">&raquo;</a></li>--%>
    <%--</ul>--%>
<%--</div>--%>

<div class="pagination pagination-centered">
    <ul>
        <c:choose>
            <c:when test="${page == 1}">
                <li class="disabled"><a href="#">&lt;&lt;</a></li>
                <li class="disabled"><a href="#">&lt;</a></li>
            </c:when>
            <c:otherwise>
                <li><a href="${firstUrl}">&lt;&lt;</a></li>
                <li><a href="${prevUrl}">&lt;</a></li>
            </c:otherwise>
        </c:choose>
        <c:forEach var="i" begin="${beginPage}" end="${endPage}">
            <c:url var="pageUrl" value="${baseUrl}">
                <c:param name="page" value="${i}"/>
            </c:url>
            <c:choose>
                <c:when test="${i == page}">
                    <li class="active"><a href="${pageUrl}"><c:out value="${i}" /></a></li>
                </c:when>
                <c:otherwise>
                    <li><a href="${pageUrl}"><c:out value="${i}" /></a></li>
                </c:otherwise>
            </c:choose>
        </c:forEach>
        <c:choose>
            <c:when test="${page == totalPages}">
                <li class="disabled"><a href="#">&gt;</a></li>
                <li class="disabled"><a href="#">&gt;&gt;</a></li>
            </c:when>
            <c:otherwise>
                <li><a href="${nextUrl}">&gt;</a></li>
                <li><a href="${lastUrl}">&gt;&gt;</a></li>
            </c:otherwise>
        </c:choose>
    </ul>
</div>